home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / iconv8_s.arc / ICONX.ARC / RSWITCH.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-11-20  |  3.5 KB  |  61 lines

  1. *-------------------------------------------------------------------------
  2. *   Context switch for Atari ST Icon
  3. *-------------------------------------------------------------------------
  4. *   Stack arrangement for a C function call
  5. *       (reference version 3.03 Lattice C Manual, page 242)
  6. *-------------------------------------------------------------------------
  7. *
  8. *                ========   SP (a7) ->  |-------------------| Low
  9. *                expression evaluation  |    temporaries    |
  10. *                                       |-------------------|
  11. *                addressed as negative  |  auto data items  |
  12. *                      offsets from FP  |     .  .  .       |
  13. *                ========   FP (a6) ->  |-------------------|
  14. *                called routine pushes  | caller's saved FP |
  15. *                                       |-------------------|
  16. *                pushed by jsr          |  return address   |
  17. *                                       |-------------------|
  18. *                first argument is      |    arguments      |
  19. *                a6 plus 8 bytes        |     .  .  .       |
  20. *                old SP value   ----->  |-------------------| High
  21. *
  22. *-------------------------------------------------------------------------
  23.         text                         control section for instructions
  24.         xdef    coswitch
  25.         xref    interp
  26.         xref    syserr
  27. *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
  28. coswitch  equ  *
  29.         link    a6,#0                push frame pointer & allocate no locals
  30.         move.l  8(a6),a0             a0 = address of old_cs
  31.         move.l  12(a6),a1            a1 = address of new_cs
  32.         move.l  a7,(a0)              store stack pointer in old_cs
  33.         movem.l d2-d7/a2-a6,4(a0)    store needed registers in old_cs
  34.         move.l  (a1),a7              load stack pointer from new_cs
  35.         tst.l   16(a6)               if(first == 0) {
  36.         bne     nofirst
  37.         moveq   #0,d0                    zero return value
  38.         move.l  d0,a6                    zero frame pointer
  39.         move.l  d0,-(a7)                 push two zero arguments
  40.         move.l  d0,-(a7)                    for interp()
  41.         jsr     interp                   call interp()
  42.         addq.l  #8,a7                    remove interp() args from stack
  43.         pea     mesg                     push argument for syserr()
  44.         jsr     syserr                   call syserr()
  45. *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
  46. *  Following instructions not needed because syserr() never returns         *
  47. *                                                                           *
  48. *       addq.l  #4,a7                    remove syserr() args from stack    *
  49. *       bra     done                 } else                                 *
  50. *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
  51. nofirst equ     *
  52.         movem.l 4(a1),d2-d7/a2-a6        restore preserved regs from new_cs
  53. *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
  54. done    equ     *
  55.         unlk    a6                   restore frame pointer from stack
  56.         rts                          return to calling program
  57. *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
  58.         data                         control section for initialized statics
  59. mesg    dc.b    'interp() returned in coswitch',0
  60.         end
  61.